﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="DisplaySearchResults.aspx.cs" Inherits="CodeDemon.Views.Review.DisplaySearchResults" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

    <h2>Search Results</h2>
    
    <%
        var list = from reviews in ViewData.Model.DAO.Reviews
            join status in ViewData.Model.DAO.ReviewStatus on reviews.ReviewStatusID equals status.ReviewStatusID
            join users in ViewData.Model.DAO.Users on reviews.ReviewOwnerID equals users.UserID
            where System.Data.Linq.SqlClient.SqlMethods.Like(reviews.Description, ViewData.Model.VarHash["reviewDesc"])
			        && System.Data.Linq.SqlClient.SqlMethods.Like(reviews.Title, ViewData.Model.VarHash["reviewTitle"])
            orderby reviews.ReviewCreatedTimeStamp descending
            select new
            {
                reviews.ReviewID,
                reviews.Title,
                reviews.Description,
                status.StatusName,
                reviews.ReviewCreatedTimeStamp,
                reviews.DefectNumber,
                reviews.ReviewStatusID,
                reviews.ReviewOwnerID,
                users.RealName
            };

        if (ViewData.Model.VarHash["filterByStatus"] == "yes")
        {
            var list2 = from lists in list where lists.ReviewStatusID.ToString() == ViewData.Model.VarHash["reviewStatusID"] select lists;
            list = list2;
        }

        if (ViewData.Model.VarHash["filterByOwner"] == "yes")
        {
            var list2 = from lists2 in list where lists2.ReviewOwnerID.ToString() == ViewData.Model.VarHash["reviewOwnerID"] select lists2;
            list = list2;
        }

        Response.Write("<table class='tablesorter' id='myTable'><thead><tr><th nowrap='true'>Title</th><th>Description</th><th nowrap='true' width='10%'>Owner</th><th width='10%'>Status</th><th width='6%'>ReviewID</th><th nowrap='true' width='6%'>Defect ID</th><th nowrap='true' width='8%'>Timestamp</th></tr></thead><tbody>");
        foreach (var review in list)
        {

            Response.Write(String.Format("<tr><td>{0}</td>", Html.ActionLink(review.Title, "DisplayReview", "Review", new { reviewId = review.ReviewID }, null)));
            Response.Write(String.Format("<td>{1}</td><td>{7}</td><td>{2}</td><td>{3}</td><td><a href='{6}{4}'>{4}</a></td><td>{5}</td></tr>", review.Title, review.Description, review.StatusName, review.ReviewID, review.DefectNumber, review.ReviewCreatedTimeStamp, ConfigurationManager.AppSettings["DefectSystem_LookupURL"],review.RealName));
        }
        Response.Write("</tbody></table>");
        
    %>
        <script type="text/javascript">
        $(document).ready(function() 
        { 
             $("#myTable").tablesorter({widthFixed: true, widgets: ['zebra']});  
        } ); 
    </script>


</asp:Content>
